﻿// =================================================================== 
// 项目说明
//====================================================================
// Wup。@Copy Right 2014
// 文件： Feedback.cs
// 项目名称：买车网
// 创建时间：2014/7/20
// 负责人：Wup
// ===================================================================
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Text;
using Weixin.Entity.ChinaTax;
using Weixin.Utils;


namespace Weixin.DAL.ChinaTax
{
    /// <summary>
    /// 数据层实例化接口类 dbo.Feedback.
    /// </summary>
    public partial class FeedbackDataAccessLayer 
    {
		#region 构造函数


		/// <summary>
		/// 
		/// </summary>
		public FeedbackDataAccessLayer()
		{
		}
		#endregion

        #region -----------实例化接口函数-----------
		
		#region 添加更新删除
		/// <summary>
		/// 向数据库中插入一条新记录。
		/// </summary>
		/// <param name="_FeedbackModel">Feedback实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(FeedbackEntity _FeedbackModel)
		{
			string sqlStr="insert into Feedback([Id],[Name],[Sex],[Mobile],[Email],[Province],[City],[Address],[CreateTime],[UserName],[Detail]) values(@Id,@Name,@Sex,@Mobile,@Email,@Province,@City,@Address,@CreateTime,@UserName,@Detail) select @Id";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@Id",SqlDbType.Int),
			new SqlParameter("@Name",SqlDbType.VarChar),
			new SqlParameter("@Sex",SqlDbType.Int),
			new SqlParameter("@Mobile",SqlDbType.VarChar),
			new SqlParameter("@Email",SqlDbType.VarChar),
			new SqlParameter("@Province",SqlDbType.VarChar),
			new SqlParameter("@City",SqlDbType.VarChar),
			new SqlParameter("@Address",SqlDbType.VarChar),
			new SqlParameter("@CreateTime",SqlDbType.DateTime),
			new SqlParameter("@UserName",SqlDbType.VarChar),
			new SqlParameter("@Detail",SqlDbType.VarChar)
			};			
			_param[0].Value=_FeedbackModel.Id;
			_param[1].Value=_FeedbackModel.Name;
			_param[2].Value=_FeedbackModel.Sex;
			_param[3].Value=_FeedbackModel.Mobile;
			_param[4].Value=_FeedbackModel.Email;
			_param[5].Value=_FeedbackModel.Province;
			_param[6].Value=_FeedbackModel.City;
			_param[7].Value=_FeedbackModel.Address;
			_param[8].Value=_FeedbackModel.CreateTime;
			_param[9].Value=_FeedbackModel.UserName;
			_param[10].Value=_FeedbackModel.Detail;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
			return res;
		}
		/// <summary>
		/// 向数据库中插入一条新记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_FeedbackModel">Feedback实体</param>
		/// <returns>新插入记录的编号</returns>
		public int Insert(SqlTransaction sp,FeedbackEntity _FeedbackModel)
		{
			string sqlStr="insert into Feedback([Id],[Name],[Sex],[Mobile],[Email],[Province],[City],[Address],[CreateTime],[UserName],[Detail]) values(@Id,@Name,@Sex,@Mobile,@Email,@Province,@City,@Address,@CreateTime,@UserName,@Detail) select @Id";
			int res;
			SqlParameter[] _param={
			new SqlParameter("@Id",SqlDbType.Int),
			new SqlParameter("@Name",SqlDbType.VarChar),
			new SqlParameter("@Sex",SqlDbType.Int),
			new SqlParameter("@Mobile",SqlDbType.VarChar),
			new SqlParameter("@Email",SqlDbType.VarChar),
			new SqlParameter("@Province",SqlDbType.VarChar),
			new SqlParameter("@City",SqlDbType.VarChar),
			new SqlParameter("@Address",SqlDbType.VarChar),
			new SqlParameter("@CreateTime",SqlDbType.DateTime),
			new SqlParameter("@UserName",SqlDbType.VarChar),
			new SqlParameter("@Detail",SqlDbType.VarChar)
			};			
			_param[0].Value=_FeedbackModel.Id;
			_param[1].Value=_FeedbackModel.Name;
			_param[2].Value=_FeedbackModel.Sex;
			_param[3].Value=_FeedbackModel.Mobile;
			_param[4].Value=_FeedbackModel.Email;
			_param[5].Value=_FeedbackModel.Province;
			_param[6].Value=_FeedbackModel.City;
			_param[7].Value=_FeedbackModel.Address;
			_param[8].Value=_FeedbackModel.CreateTime;
			_param[9].Value=_FeedbackModel.UserName;
			_param[10].Value=_FeedbackModel.Detail;
			res = Convert.ToInt32(SqlHelper.ExecuteScalar(sp,CommandType.Text,sqlStr,_param));
			return res;
		}


		/// <summary>
		/// 向数据表Feedback更新一条记录。
		/// </summary>
		/// <param name="_FeedbackModel">_FeedbackModel</param>
		/// <returns>影响的行数</returns>
		public int Update(FeedbackEntity _FeedbackModel)
		{
            string sqlStr="update Feedback set [Name]=@Name,[Sex]=@Sex,[Mobile]=@Mobile,[Email]=@Email,[Province]=@Province,[City]=@City,[Address]=@Address,[CreateTime]=@CreateTime,[UserName]=@UserName,[Detail]=@Detail where Id=@Id";
			SqlParameter[] _param={				
				new SqlParameter("@Id",SqlDbType.Int),
				new SqlParameter("@Name",SqlDbType.VarChar),
				new SqlParameter("@Sex",SqlDbType.Int),
				new SqlParameter("@Mobile",SqlDbType.VarChar),
				new SqlParameter("@Email",SqlDbType.VarChar),
				new SqlParameter("@Province",SqlDbType.VarChar),
				new SqlParameter("@City",SqlDbType.VarChar),
				new SqlParameter("@Address",SqlDbType.VarChar),
				new SqlParameter("@CreateTime",SqlDbType.DateTime),
				new SqlParameter("@UserName",SqlDbType.VarChar),
				new SqlParameter("@Detail",SqlDbType.VarChar)
				};				
				_param[0].Value=_FeedbackModel.Id;
				_param[1].Value=_FeedbackModel.Name;
				_param[2].Value=_FeedbackModel.Sex;
				_param[3].Value=_FeedbackModel.Mobile;
				_param[4].Value=_FeedbackModel.Email;
				_param[5].Value=_FeedbackModel.Province;
				_param[6].Value=_FeedbackModel.City;
				_param[7].Value=_FeedbackModel.Address;
				_param[8].Value=_FeedbackModel.CreateTime;
				_param[9].Value=_FeedbackModel.UserName;
				_param[10].Value=_FeedbackModel.Detail;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		/// <summary>
		/// 向数据表Feedback更新一条记录。带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
		/// <param name="_FeedbackModel">_FeedbackModel</param>
		/// <returns>影响的行数</returns>
		public int Update(SqlTransaction sp,FeedbackEntity _FeedbackModel)
		{
            string sqlStr="update Feedback set [Name]=@Name,[Sex]=@Sex,[Mobile]=@Mobile,[Email]=@Email,[Province]=@Province,[City]=@City,[Address]=@Address,[CreateTime]=@CreateTime,[UserName]=@UserName,[Detail]=@Detail where Id=@Id";
			SqlParameter[] _param={				
				new SqlParameter("@Id",SqlDbType.Int),
				new SqlParameter("@Name",SqlDbType.VarChar),
				new SqlParameter("@Sex",SqlDbType.Int),
				new SqlParameter("@Mobile",SqlDbType.VarChar),
				new SqlParameter("@Email",SqlDbType.VarChar),
				new SqlParameter("@Province",SqlDbType.VarChar),
				new SqlParameter("@City",SqlDbType.VarChar),
				new SqlParameter("@Address",SqlDbType.VarChar),
				new SqlParameter("@CreateTime",SqlDbType.DateTime),
				new SqlParameter("@UserName",SqlDbType.VarChar),
				new SqlParameter("@Detail",SqlDbType.VarChar)
				};				
				_param[0].Value=_FeedbackModel.Id;
				_param[1].Value=_FeedbackModel.Name;
				_param[2].Value=_FeedbackModel.Sex;
				_param[3].Value=_FeedbackModel.Mobile;
				_param[4].Value=_FeedbackModel.Email;
				_param[5].Value=_FeedbackModel.Province;
				_param[6].Value=_FeedbackModel.City;
				_param[7].Value=_FeedbackModel.Address;
				_param[8].Value=_FeedbackModel.CreateTime;
				_param[9].Value=_FeedbackModel.UserName;
				_param[10].Value=_FeedbackModel.Detail;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}		
		
		
		/// <summary>
		/// 删除数据表Feedback中的一条记录
		/// </summary>
	    /// <param name="Id">id</param>
		/// <returns>影响的行数</returns>
		public int Delete(int Id)
		{
			string sqlStr="delete from Feedback where [Id]=@Id";
			SqlParameter[] _param={			
			new SqlParameter("@Id",SqlDbType.Int),
			
			};			
			_param[0].Value=Id;
			return SqlHelper.ExecuteNonQuery(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param);
		}
		
		/// <summary>
		/// 删除数据表Feedback中的一条记录,带事务
		/// </summary>
		/// <param name="sp">事务对象</param>
	    /// <param name="Id">id</param>
		/// <returns>影响的行数</returns>
		public int Delete(SqlTransaction sp,int Id)
		{
			string sqlStr="delete from Feedback where [Id]=@Id";
			SqlParameter[] _param={			
			new SqlParameter("@Id",SqlDbType.Int),
			
			};			
			_param[0].Value=Id;
			return SqlHelper.ExecuteNonQuery(sp,CommandType.Text,sqlStr,_param);
		}
		#endregion
		
		#region 数据实体
		/// <summary>
		/// 得到  feedback 数据实体
		/// </summary>
		/// <param name="row">row</param>
		/// <returns>feedback 数据实体</returns>
		public FeedbackEntity Populate_FeedbackEntity_FromDr(DataRow row)
		{
			FeedbackEntity Obj = new FeedbackEntity();
			if(row!=null)
			{
				Obj.Id = (( row["Id"])==DBNull.Value)?0:Convert.ToInt32( row["Id"]);
				Obj.Name =  row["Name"].ToString();
				Obj.Sex = (( row["Sex"])==DBNull.Value)?0:Convert.ToInt32( row["Sex"]);
				Obj.Mobile =  row["Mobile"].ToString();
				Obj.Email =  row["Email"].ToString();
				Obj.Province =  row["Province"].ToString();
				Obj.City =  row["City"].ToString();
				Obj.Address =  row["Address"].ToString();
				Obj.CreateTime = (( row["CreateTime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( row["CreateTime"]);
				Obj.UserName =  row["UserName"].ToString();
				Obj.Detail =  row["Detail"].ToString();
			}
			else
			{
				return null;
			}
			return Obj;
		}
		
        /// <summary>
		/// 得到  feedback 数据实体
		/// </summary>
		/// <param name="dr">dr</param>
		/// <returns>feedback 数据实体</returns>
		public FeedbackEntity Populate_FeedbackEntity_FromDr(IDataReader dr)
		{
			FeedbackEntity Obj = new FeedbackEntity();
			
				Obj.Id = (( dr["Id"])==DBNull.Value)?0:Convert.ToInt32( dr["Id"]);
				Obj.Name =  dr["Name"].ToString();
				Obj.Sex = (( dr["Sex"])==DBNull.Value)?0:Convert.ToInt32( dr["Sex"]);
				Obj.Mobile =  dr["Mobile"].ToString();
				Obj.Email =  dr["Email"].ToString();
				Obj.Province =  dr["Province"].ToString();
				Obj.City =  dr["City"].ToString();
				Obj.Address =  dr["Address"].ToString();
				Obj.CreateTime = (( dr["CreateTime"])==DBNull.Value)?Convert.ToDateTime("1900-1-1"):Convert.ToDateTime( dr["CreateTime"]);
				Obj.UserName =  dr["UserName"].ToString();
				Obj.Detail =  dr["Detail"].ToString();
			
			return Obj;
		}
		#endregion
		
		/// <summary>
		/// 根据ID,返回一个Feedback对象
		/// </summary>
		/// <param name="id">id</param>
		/// <returns>Feedback对象</returns>
		public FeedbackEntity Get_FeedbackEntity (int id)
		{
			FeedbackEntity _obj=null;
			SqlParameter[] _param={
			new SqlParameter("@Id",SqlDbType.Int)
			};
			_param[0].Value=id;
			string sqlStr="select * from Feedback with(nolock) where Id=@Id";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param))
			{
				while(dr.Read())
				{
            		_obj=Populate_FeedbackEntity_FromDr(dr);
				}
			}
			return _obj;
		}
		/// <summary>
		/// 得到数据表Feedback所有记录
		/// </summary>
		/// <returns>数据集</returns>
		public IList< FeedbackEntity> Get_FeedbackAll()
		{
			IList< FeedbackEntity> Obj=new List< FeedbackEntity>();
			string sqlStr="select * from Feedback";
			using(SqlDataReader dr=SqlHelper.ExecuteReader(WebConfig.ChinaTax,CommandType.Text,sqlStr))
			{
				while(dr.Read())
				{
					Obj.Add(Populate_FeedbackEntity_FromDr(dr));
				}
			}
			return Obj;
		}
		/// <summary>
        /// 检测是否存在根据主键
        /// </summary>
        /// <param name="id">id</param>
        /// <returns>是/否</returns>
		public bool IsExistFeedback(int id)
		{
			SqlParameter[] _param={
                                      new SqlParameter("@id",SqlDbType.Int)
                                  };
            _param[0].Value=id;
            string sqlStr="select Count(*) from Feedback where Id=@id";
            int a=Convert.ToInt32(SqlHelper.ExecuteScalar(WebConfig.ChinaTax,CommandType.Text,sqlStr,_param));
            if(a>0)
            {
                return true;
            }
            else
            {
                return false;
            }
		}

        #endregion
		
		#region----------自定义实例化接口函数----------
		#endregion
    }
}
